package com.xidian.zhiancloud.controller.myyb;

import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.SysRoleTable;
import com.xidian.zhiancloud.model.SysUserAbandon;
import com.xidian.zhiancloud.service.myyb.IRoleTableService;
import com.xidian.zhiancloud.service.myyb.ISysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 系统设置-角色管理
 *
 */
@RestController
@RequestMapping("/roleTable")
public class RoleTableController {

    private final static Logger logger = LoggerFactory.
            getLogger(RoleTableController.class);

    @Autowired
    private IRoleTableService roleTableService;

    @Autowired
    private ISysUserService userService;

    /**
     * 角色管理列表
     * @param roleId 角色ID
     * @param username 用户名称
     * @param phoneNum 用户手机号
     * @param department 部门
     * @param position 职位
     * @param post 岗位
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/roleTable_list")
    public ResultDTO<List<SysRoleTable>> selectRoleTableList(
            @RequestParam("roleId") Long roleId,
           @RequestParam("username") String username,
           @RequestParam("phoneNum") String phoneNum,
           @RequestParam("department") String department,
           @RequestParam("position") String position, @RequestParam("post") String post) {
        String roleTableStatus = "0";
        Map<String, Object> mapResult = new HashMap<String, Object>();
        mapResult.put("roleTableStatus", roleTableStatus);
        List<SysRoleTable> roleTableList = roleTableService.selectRoleTableList(mapResult);
        SysUserAbandon user = new SysUserAbandon();
        for (SysRoleTable roleTable : roleTableList) {
            user = userService.selectByPrimaryKey(roleTable.getId());
        }
        return ResultDTO.successOf(roleTableService.selectRoleTableList(mapResult),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 删除角色
     * @param id 角色ID
     * @return 返回 ResultDTO 对象
     */
    @GetMapping("/deleteRoleTable")
    public ResultDTO<Boolean> deleteRoleTable(@RequestParam("id") Long id){
        roleTableService.deleteRoleTableById(id);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 编辑
     * @param roleTable 编辑角色的内容
     * @return 返回 ResultDTO 对象
     */
    @PatchMapping("/patchById")
    public ResultDTO<Boolean> patchById(SysRoleTable roleTable) {
        roleTableService.patchById(roleTable);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 添加
     * @param roleTable 添加角色的内容
     * @return 返回 ResultDTO 对象
     */
    @PostMapping("/add")
    public ResultDTO<Boolean> add(SysRoleTable roleTable) {
        roleTableService.add(roleTable);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }




}
